Skip to content

feat: track API usage in Vercel Web Analytics - #222

Merged
guillaumegay13 merged 4 commits into
mainfrom
feat/api-usage-tracking
Aug 24, 2026
Merged

feat: track API usage in Vercel Web Analytics#222
guillaumegay13 merged 4 commits into
mainfrom
feat/api-usage-tracking

Conversation

@brunobuddy

Copy link
Copy Markdown
Member

💭 Why

The analytics script only runs on HTML pages. The JSON API is static files fetched by curl and SDKs, so we had no visibility into which endpoints and models get used.

✨ What changed

  • Edge middleware posts an api_request custom event per /api/* and llms.txt request.
  • Events carry endpoint, provider, model, auth mode, and client type (curl, python, node, browser).
  • Wire format copied from @vercel/analytics/server 2.0.1: the package itself can't install here (its optional SvelteKit peer wants vite 8, we're on vite 5).
  • No-op outside Vercel. README and CONTRIBUTING document the new module.

🔧 For operators

  • Custom events need a Vercel Pro plan; they show up under Analytics → Events.
  • Every API hit counts as one metered Web Analytics event.

@vercel

vercel Bot commented Aug 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
modelparams.dev Ready Ready Preview Aug 24, 2026 6:45pm

Request Review

@github-actions github-actions Bot added site Website code or tooling meta Repo docs, CI, and config labels Aug 13, 2026
The middleware matcher covered /api/* so direct hits on /api/mcp were
logged as endpoint "other", while MCP traffic on the public /mcp path
was not counted at all (middleware sees the pre-rewrite path). Match
/mcp explicitly and classify both paths as endpoint "mcp".
@guillaumegay13
guillaumegay13 merged commit 1ae09d3 into main Aug 24, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meta Repo docs, CI, and config site Website code or tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants